package com.wenjiang.controller;

import com.wenjiang.common.annotation.OperatorLog;
import com.wenjiang.common.lang.Result;
import com.wenjiang.entity.MallGoodType;
import com.wenjiang.service.MallGoodTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/goodType")
@RestController
public class GoodTypeController {

    @Autowired
    MallGoodTypeService mallGoodTypeService;


    //获取所有分类
    @RequestMapping("/all")
    public  Object getAllType(){
        Result result = mallGoodTypeService.getAllGoodType();
        return result;
    }


    //添加一个标签
    @RequestMapping("/add")
    @OperatorLog
    public  Object addGoodType(@RequestBody MallGoodType mallGoodType){
        Result result = mallGoodTypeService.addGoodType(mallGoodType);


        return  result;
    }

    //查找当前的等级的分类标签
    @RequestMapping("/currentLevel/{level}")
    public  Object getCurrentLevelType(@PathVariable(name = "level") Integer level){
        return  mallGoodTypeService.getCurrentLevelType(level);
    }

    //进入父标签的子标签
    @RequestMapping("/children/{parentId}")
    public  Object getChildrenType(@PathVariable(name = "parentId") Integer parentId){

        return mallGoodTypeService.getChildrenGoodType(parentId);
    }

    // 修改一个标签
    @RequestMapping("/update")
    @OperatorLog
    public  Object updateGoodType(@RequestBody MallGoodType mallGoodType){

        return mallGoodTypeService.updateGoodType(mallGoodType);
    }

    //删除一个标签
    @RequestMapping("/delete/{typeId}")
    @OperatorLog
    public  Object deleteGoodType(@PathVariable(name = "typeId") Integer typeId){
        return mallGoodTypeService.delGoodType(typeId);
    }

}
